package com.cci.kangdao.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import com.cci.kangdao.entity.LatestWorkOrder;

@MapperScan
public interface WorkOrderRepairDao {
	
	/**
	 * 用户通过APP创建工单
	 * @param map
	 * @return
	 */
	public int CreateWorkOrder(Map<String,Object> map);
	
	/**
	 * 记录用户行为日志
	 * @param map
	 * @return
	 */
	public int saveOperation(Map<String,Object> map);
	
	/**
	 * 取消工单
	 * @param map
	 * @return
	 */
	public int updateWorkOrderStatus(Map<String,Object> map);
	
	/**
	 * 查询需要发送短信的人员列表
	 *
	 * @param map
	 * @return
	 */
	public List<Map<String, Object>> getSendList(@Param("map") Map<String, Object> map, @Param("roleNoList") List<String> roleNoList);
	
	/**
	 * 将信息发送结果存入数据库
	 * @param list
	 * @return
	 */
	public int saveMsgOperation(List<Map<String,Object>> list);
	
	/**
	 * 如果工单流转到服务技师，查询哪个服务技师在处理
	 * @param map
	 * @return
	 */
	public Map<String,Object> getServiceTech(Map<String,Object> map);
	
	/**
	 * 根据工单Id获取工单最新状态
	 * @param map
	 * @return
	 */
	public Map<String,Object> getCurrentWorkOrder(Map<String,Object> map);
	
	/**
	 * 保存工单负责人信息
	 * @param map
	 * @return
	 */
	public int savePrincipal(Map<String,Object> map);

	/**
	 * @description: 批量 保存工单负责人信息
	 * @author: wunan
	 * @company: Pactera Technology Co.,Ltd
	 * @since: 2021/11/29 11:21
	 * @version: V1.0
	 **/
	int savePrincipalBatch(@Param("batchList") List<Map<String,Object>> batchList);

	/**
	 * 根据服务站查询服务站区域服务经理
	 * @param map
	 * @return
	 */
	public List<Map<String,Object>> getAreaManager(Map<String,Object> map);
	/**
	 * 根据服务站查询服务站区域大区经理
	 * @param map
	 * @return
	 */
	public List<Map<String,Object>> getManager(Map<String,Object> map);

	//获取ccec所有400信息
	@Select("select distinct ut.ID,ut.UserName,ut.phone,rst.clientId from Position_T pt \n" +
			"inner join PositionUser_T put on pt.ID=put.PositionID \n" +
			"inner join User_T ut on put.UserPhone=ut.Phone\n" +
			"left join RelationShip_T rst on ut.UserName=rst.UserName\n" +
			"where pt.Flag=0 and pt.Level=1 and put.Flag=0 and ut.Flag=0  and pt.Creator = #{companyId}")
	List<Map<String,Object>> getCCECAreaManager(@Param("companyId") long companyId);

	//根据服务站查询服务站指定的区域工程师(2.0.8需求)
	@Select("select distinct b.ID,b.UserName,b.phone,c.clientId from RecommendThreeStationForDBU_T a \n" +
			"inner join User_T b on a.DBEngineerPhone = b.Phone \n" +
			"left join RelationShip_T c on b.UserName = c.UserName\n" +
			"where a.OrderId = #{orderId} and a.Flag = 0 and b.Flag = 0")
	public List<Map<String,Object>> getDBUAreaManager(@Param("orderId") long orderId);

	
	/**
	 * 查询服务站经纬度，计算故障点与服务站的距离
	 * @param map
	 * @return
	 */
	public Map<String,Object> getDistance(Map<String,Object> map);
	
	/**
	 * 根据服务站Id获取bussinesNo
	 * @param stationId
	 * @return
	 */
	public Map<String,Object> getStationNoById(Map<String,Object> map);
	
	/**
	 * 获取工单副技师列表
	 * @param OrderId
	 * @return
	 */
	public List<Map<String,Object>> getServiceAssociateTechnician(String OrderId);
	
	/**
	 * 根据发动机号获取该发动机当日报修次数
	 * @param map
	 * @return
	 */
	public int getESNCount(Map<String,Object> map);

	/**
	 * 2022-12-27 根据变速箱号获取该发动机当日报修次数
	 * @param map
	 * @return
	 */
	public int getAmtNoCount(Map<String,Object> map);

	/**
	 *  通过服务站ID，获取服务站站长/信息员列表
	 * @param serviceStationId 服务站ID
	 * @return 站长/信息员列表
	 */
	List<Map<String,Object>> getServiceStationManagerList(Long serviceStationId);
	
	
	
	int countSameUnifiedRepairNoByEsn(@Param("esn")String esn, @Param("unifiedRepairNo")String unifiedRepairNo);
	
	
	LatestWorkOrder getLatestWorkOrderByEsn(String esn);
	
	int containsGivenServiceSubtypeByEsn(@Param("esn")String esn, @Param("list") List<String> list);

	int containsSubtypeByEsn(@Param("esn")String esn,@Param("healthExaminationCategory")String healthExaminationCategory,@Param("list") List<String> list);

	int containsGivenServiceSubtypeByEsnWithing(@Param("esn")String esn, @Param("list") List<String> list);

    /**
     * 更新gsn
     *
     * @param map
     * @return
     */
    int updateWorkOrderGsn(Map<String, Object> map);
}
